package com.by.toolkit.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum LiveMsgTypeEnum {

    TEXT(LiveMsgTypeEnum.TEXT_CODE, "普通文本消息", "TEXT"),
    AT_TEXT(LiveMsgTypeEnum.AT_TEXT_CODE, "@消息", "AT_TEXT"),
    ;

    private final Integer code;
    private final String msg;
    private final String alias;

    private static final Map<Integer, LiveMsgTypeEnum> MAP = Arrays.stream(LiveMsgTypeEnum.values())
            .collect(Collectors.toMap(LiveMsgTypeEnum::getCode, Function.identity()));

    private static final Map<String, Integer> ALIAS_MAP = Arrays.stream(LiveMsgTypeEnum.values())
            .collect(Collectors.toMap(LiveMsgTypeEnum::getAlias, LiveMsgTypeEnum::getCode));

    public static LiveMsgTypeEnum resolve(Integer code) {
        return MAP.get(code);
    }

    public static Integer resolveCodeByAlias(String alias) {
        return ALIAS_MAP.get(alias);
    }

    public static final int TEXT_CODE = 1;
    public static final int AT_TEXT_CODE = 2;

}
